package com.yzh.oop8;

/**
 * @author 于振晗
 * @title: Test
 * @description: TODO 测试类
 * @date 2020年08月28日
 * @path com.yzh.oop8
 */
public class Test {
    public static void main(String[] args) {


        Book book1 = new Book("王", "xiaosan", "清华大学出版社", 66);
        Book book2 = new Book("于", "xiaosan", "清华大学出版社", 66);
        Comparator comparator = new BookNameComparator();
        int compare = comparator.compare(book1, book2);
        System.out.println(compare);

        //匿名内部类
        Comparator comparator1 = new Comparator(){
            @Override
            public int compare(Object obj1, Object obj2) {
                Book book1 = (Book)obj1;
                Book book2 = (Book)obj2;
                return book1.getBookName().compareTo(book2.getBookName());
            }
        };
        int compare1 = comparator1.compare(book1, book2);
        System.out.println(compare1);
    }
}
